package edu.zut.cs.software.example.square.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import edu.zut.cs.software.example.service.impl.GenericManagerImpl;
import edu.zut.cs.software.example.square.dao.SquareDao;
import edu.zut.cs.software.example.square.domain.Square;
import edu.zut.cs.software.example.square.service.SquareManager;

/**
 * 
 * @author zhangjiahua
 *
 */

@Service
public class SquareManagerImpl extends GenericManagerImpl<Square, Long> implements SquareManager {

	private static final List<Square> Square = null;
	SquareDao squareDao;

	/*
	 * @Override public List<Space> findBymessage(String message) { // 创建查询条件数据对象
	 * Space queryObject=new Space(); queryObject.setMessage(message); //
	 * 创建匹配器，即如何使用查询条件 ExampleMatcher matcher = ExampleMatcher.matching() // 构建对象
	 * .withStringMatcher(StringMatcher.CONTAINING) // 改变默认字符串匹配方式：模糊查询
	 * .withMatcher("message", GenericPropertyMatchers.contains()) //
	 * 姓名采用“开始匹配”的方式查询 .withIgnorePaths("dateCreated", "dateModified"); //
	 * 忽略属性：是否关注。因为是基本类型，需要忽略掉
	 * 
	 * 
	 * // 创建实例并查询 Example<Space> ex = Example.of(queryObject, matcher); List<Space>
	 * result = this.spaceDao.findAll(ex); return result; }
	 */

	@Autowired
	public void setSquareDao(SquareDao squareDao) {
		this.squareDao = squareDao;
		this.dao = this.squareDao;
	}

	@Override
	public List<Square> getBySquare(int pagenum, int pageSize) {
		List<Square> Square= squareDao.getBySquare(pagenum,pageSize );
		return Square;
	}
	@Override
	public int getSquareCounts() {
		int numbers = squareDao.getSquareCounts();
		return numbers;
	}

	@Override
	public int getSquareBytitleCounts(String title) {
		int numbers = squareDao.getSquareBytitleCounts(title);
		return numbers;
	}


	@Override
	public List<Square> findBytitle(String title, int pagenum, int pageSize) {
		List<Square> Square= squareDao.findBytitle(title, pagenum, pageSize);
		return Square;
	}
    
	
	@Override
	public int deleteById(int id) {
		int i=squareDao.deleteById(id);
		return i;
	}

	@Override
	public Square getUpdateSquService(int id) {
		return squareDao.getUpdateSquare(id);
	}
	
	@Override
	public int editsquare(Square square) {
		Long ID=square.getId();
		String content=square.getContent();
		String title=square.getTitle();
		
		return squareDao.editsquare(content, title,ID);
	}

	
}
